package com.xk.mapper;


import com.xk.pojo.Classes;
import com.xk.pojo.Teacher;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ClassMapper {

    @Select("SELECT c.*, t.Name AS teacherName FROM Classes c " +
            "LEFT JOIN Teacher t ON c.TeacherID = t.TeacherID;")
    List<Classes> getAllClasses();


    int addClass(Classes classes);


    //获取第pageNumber页，每页显示的记录数为pageSize的班级列表,名字里包含search的

    @Select("SELECT c.*, t.Name AS teacherName FROM Classes c " +
            "LEFT JOIN Teacher t ON c.TeacherID = t.TeacherID " +
            "WHERE c.ClassName LIKE CONCAT('%', #{search}, '%') " +
            "LIMIT #{pageNumber}, #{pageSize}")
    List<Classes> getClassesListByPage(@Param("pageNumber") Integer pageNumber,
                                       @Param("pageSize")Integer pageSize,
                                       @Param("search")String search);

    @Select("SELECT * FROM classes WHERE ClassName LIKE CONCAT('%', #{name}, '%')")
    List<Classes> getClassesByName(String search);

    @Delete("DELETE FROM classes WHERE ClassID = #{id};")
    int deleteClassById(Integer id);

    int updateClassesById(Classes classes);

    @Select("SELECT * FROM classes WHERE TeacherID = #{id}")
    List<Classes> getClassesByTeacherID(Integer id);

}
